package org.example.service.impl;


import org.example.Contant.BusinessException;
import org.example.entity.Resume;
import org.example.mapper.ResumeMapper;
import org.example.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ResumeServiceImpl implements ResumeService {

    @Autowired
    private ResumeMapper resumeMapper;
    /**
     * 插入新的简历
     * @param userId
     * @param info
     * @return
     */
    @Override
    public int insertResume(int userId, String info) {
        Resume resume = new Resume();
        resume.setInfo(info);
        //插入简历信息
        int result1 = resumeMapper.insertResume(resume);
        if (result1 <= 0){
            throw new BusinessException("500","插入简历信失败");
        }
        int resumeId = resume.getId();
        int result2 = resumeMapper.insertUserResume(userId, resumeId);
        if (result2 <= 0){
            throw new BusinessException("500","插入关联表失败");
        }
        return 1;
    }

    /**
     * 根据userId获取最新的简历信息
     * @param userId
     * @return
     */
    @Override
    public String getInfoByUserIdNew(int userId) {
        //根据userId查询最新的简历信息
        String info = resumeMapper.getInfoByUserIdNew(userId);
        if ("".equals(info)){
            throw new BusinessException("500","未查询到简历信息");
        }
        return info;
    }
}
